import java.util.ArrayList;

public class Tester {

	public static void main (String[] args)
	{
		runTests();
	}
	public static void runTests()
	{
		testRules();
		testWinners();
	}

	private static void testRules()
	{
		int totalTests = 0;
		int testsPassed = 0;
		Hand hand;

		/*
		//High
		ArrayList<Card> high = new ArrayList<Card>();
		high.add(new Card(Card.Suit.CLUB, 14));
		high.add(new Card(Card.Suit.SPADE, 2));
		high.add(new Card(Card.Suit.CLUB, 3));
		high.add(new Card(Card.Suit.CLUB, 4));
		high.add(new Card(Card.Suit.CLUB, 5));
		high.add(new Card(Card.Suit.SPADE, 7));
		high.add(new Card(Card.Suit.DIAMOND, 9));
		hand = Hand.getBestHand(high);

		if (hand.highCard().value == 14)
			testsPassed++;
		else
			System.out.println("High Card: "+(hand.highCard().value == 14));
		totalTests++;
		*/

		//Pair
		ArrayList<Card> pair = new ArrayList<Card>();
		pair.add(new Card(Card.Suit.CLUB, 14));
		pair.add(new Card(Card.Suit.SPADE, 14));
		hand = Hand.getBestHand(pair);

		if (hand.getType() == Hand.PAIR)
			testsPassed++;
		else
			System.out.println("Pair: "+(hand.getType() == Hand.PAIR));
		totalTests++;
		pair.add(new Card(Card.Suit.CLUB, 3));
		hand = Hand.getBestHand(pair);

		if (hand.getType() == Hand.PAIR)
			testsPassed++;
		else
			System.out.println("Pair: "+(hand.getType() == Hand.PAIR));
		totalTests++;
		pair.add(new Card(Card.Suit.CLUB, 4));
		hand = Hand.getBestHand(pair);

		if (hand.getType() == Hand.PAIR)
			testsPassed++;
		else
			System.out.println("Pair: "+(hand.getType() == Hand.PAIR));
		totalTests++;
		pair.add(new Card(Card.Suit.CLUB, 5));
		pair.add(new Card(Card.Suit.SPADE, 7));
		pair.add(new Card(Card.Suit.DIAMOND, 9));
		hand = Hand.getBestHand(pair);

		if (hand.getType() == Hand.PAIR)
			testsPassed++;
		else
			System.out.println("Pair: "+(hand.getType() == Hand.PAIR));
		totalTests++;

		//2pair
		ArrayList<Card> twoPair = new ArrayList<Card>();
		twoPair.add(new Card(Card.Suit.CLUB, 14));
		twoPair.add(new Card(Card.Suit.SPADE, 14));
		twoPair.add(new Card(Card.Suit.CLUB, 2));
		twoPair.add(new Card(Card.Suit.HEART, 2));
		hand = Hand.getBestHand(twoPair);

		if (hand.getType() == Hand.TWO_PAIR)
			testsPassed++;
		else
			System.out.println("Two Pair: "+(hand.getType() == Hand.TWO_PAIR));
		totalTests++;
		twoPair.add(new Card(Card.Suit.CLUB, 5));
		twoPair.add(new Card(Card.Suit.SPADE, 7));
		twoPair.add(new Card(Card.Suit.DIAMOND, 9));
		hand = Hand.getBestHand(twoPair);

		if (hand.getType() == Hand.TWO_PAIR)
			testsPassed++;
		else
			System.out.println("Two Pair: "+(hand.getType() == Hand.TWO_PAIR));
		totalTests++;

		//3 of a kind
		ArrayList<Card> three = new ArrayList<Card>();
		three.add(new Card(Card.Suit.CLUB, 2));
		three.add(new Card(Card.Suit.SPADE, 2));
		three.add(new Card(Card.Suit.HEART, 2));
		hand = Hand.getBestHand(three);

		if (hand.getType() == Hand.THREE_OF_A_KIND)
			testsPassed++;
		else
			System.out.println("Three of a Kind: "+(hand.getType() == Hand.THREE_OF_A_KIND));
		totalTests++;
		three.add(new Card(Card.Suit.CLUB, 4));
		hand = Hand.getBestHand(three);

		if (hand.getType() == Hand.THREE_OF_A_KIND)
			testsPassed++;
		else
			System.out.println("Three of a Kind: "+(hand.getType() == Hand.THREE_OF_A_KIND));
		totalTests++;
		three.add(new Card(Card.Suit.CLUB, 5));
		three.add(new Card(Card.Suit.SPADE, 7));
		three.add(new Card(Card.Suit.SPADE, 9));
		hand = Hand.getBestHand(three);

		if (hand.getType() == Hand.THREE_OF_A_KIND)
			testsPassed++;
		else
			System.out.println("Three of a Kind: "+(hand.getType() == Hand.THREE_OF_A_KIND));
		totalTests++;

		//straight
		ArrayList<Card> straight = new ArrayList<Card>();
		straight.add(new Card(Card.Suit.DIAMOND, 9));
		straight.add(new Card(Card.Suit.HEART, 8));
		straight.add(new Card(Card.Suit.CLUB, 6));
		straight.add(new Card(Card.Suit.CLUB, 2));
		straight.add(new Card(Card.Suit.SPADE, 3));
		straight.add(new Card(Card.Suit.CLUB, 4));
		straight.add(new Card(Card.Suit.CLUB, 5));

		hand = Hand.getBestHand(straight);

		if (hand.getType() == Hand.STRAIGHT)
			testsPassed++;
		else
			System.out.println("Straight: "+(hand.getType() == Hand.STRAIGHT));
		totalTests++;

		//flush
		ArrayList<Card> flush = new ArrayList<Card>();
		flush.add(new Card(Card.Suit.SPADE, 7));
		flush.add(new Card(Card.Suit.CLUB, 2));
		flush.add(new Card(Card.Suit.CLUB, 3));
		flush.add(new Card(Card.Suit.CLUB, 4));
		flush.add(new Card(Card.Suit.CLUB, 6));
		flush.add(new Card(Card.Suit.CLUB, 7));
		flush.add(new Card(Card.Suit.DIAMOND, 7));
		hand = Hand.getBestHand(flush);

		if (hand.getType() == Hand.FLUSH)
			testsPassed++;
		else
			System.out.println("Flush: "+(hand.getType() == Hand.FLUSH));
		totalTests++;

		//fullhouse
		ArrayList<Card> fullHouse = new ArrayList<Card>();
		fullHouse.add(new Card(Card.Suit.SPADE, 3));
		fullHouse.add(new Card(Card.Suit.CLUB, 2));
		fullHouse.add(new Card(Card.Suit.SPADE, 2));
		fullHouse.add(new Card(Card.Suit.HEART, 2));
		fullHouse.add(new Card(Card.Suit.CLUB, 3));
		fullHouse.add(new Card(Card.Suit.HEART, 3));
		fullHouse.add(new Card(Card.Suit.CLUB, 4));
		hand = Hand.getBestHand(fullHouse);

		if (hand.getType() == Hand.FULL_HOUSE)
			testsPassed++;
		else
			System.out.println("Full House: "+(hand.getType() == Hand.FULL_HOUSE));
		totalTests++;

		//four of a kind
		ArrayList<Card> four = new ArrayList<Card>();

		four.add(new Card(Card.Suit.DIAMOND, 7));
		four.add(new Card(Card.Suit.CLUB, 7));
		four.add(new Card(Card.Suit.CLUB, 2));
		four.add(new Card(Card.Suit.SPADE, 2));
		four.add(new Card(Card.Suit.DIAMOND, 2));
		four.add(new Card(Card.Suit.HEART, 2));
		four.add(new Card(Card.Suit.CLUB, 5));
		hand = Hand.getBestHand(four);

		if (hand.getType() == Hand.FOUR_OF_A_KIND)
			testsPassed++;
		else
			System.out.println("Four of a Kind: "+(hand.getType() == Hand.FOUR_OF_A_KIND));
		totalTests++;

		//straight flush
		ArrayList<Card> straightFlush = new ArrayList<Card>();
		straightFlush.add(new Card(Card.Suit.HEART, 13));
		straightFlush.add(new Card(Card.Suit.DIAMOND, 13));
		straightFlush.add(new Card(Card.Suit.CLUB, 14));
		straightFlush.add(new Card(Card.Suit.CLUB, 10));
		straightFlush.add(new Card(Card.Suit.CLUB, 11));
		straightFlush.add(new Card(Card.Suit.CLUB, 12));
		straightFlush.add(new Card(Card.Suit.CLUB, 13));
		//hand = Hand.straight(straightFlush);
		//System.out.println(hand);
		hand = Hand.getBestHand(straightFlush);

		if (hand.getType() == Hand.STRAIGHT_FLUSH)
			testsPassed++;
		else
			System.out.println("Straight Flush: "+(hand.getType() == Hand.STRAIGHT_FLUSH));
		totalTests++;

		System.out.println("Hand tests passed: "+testsPassed+"/"+totalTests);

	}

	private static void testWinners()
	{
		int totalTests = 1;
		int testsPassed = 0;

		ArrayList<Card> high = new ArrayList<Card>();
		high.add(new Card(Card.Suit.SPADE, 3));
		high.add(new Card(Card.Suit.CLUB, 10));
		high.add(new Card(Card.Suit.SPADE, 12));
		high.add(new Card(Card.Suit.SPADE, 9));
		high.add(new Card(Card.Suit.SPADE, 10));
		high.add(new Card(Card.Suit.HEART, 10));
		high.add(new Card(Card.Suit.DIAMOND, 10));

		ArrayList<Card> low = new ArrayList<Card>();
		low.add(new Card(Card.Suit.SPADE, 3));
		low.add(new Card(Card.Suit.CLUB, 10));
		low.add(new Card(Card.Suit.SPADE, 12));
		low.add(new Card(Card.Suit.SPADE, 9));
		low.add(new Card(Card.Suit.SPADE, 10));
		low.add(new Card(Card.Suit.CLUB, 3));
		low.add(new Card(Card.Suit.HEART, 12));

		int result = Hand.getBestHand(high).compareTo(Hand.getBestHand(low));
		if (result == 1)
			testsPassed++;
		System.out.println("Hand tests passed: "+testsPassed+"/"+totalTests);
	}

}
